package com.baide.xguangji.swing;

import com.baide.xguangji.plc.NioServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 当初始化完成时，直接执行代码，启动ct客户端，监听称重机485，启动obr和plc 的server
 * 并 设置回调
 *
 * @author 隔壁老王
 */
@Component
public class AfterServiceStarted implements ApplicationRunner {
    @Autowired
    MainContent mainContent;
    @Autowired
    NioServer plcServer;//plc和相机

    @Override
    public void run(ApplicationArguments args) throws Exception {
        ExecutorService pool = Executors.newFixedThreadPool(3);
        plcServer.setCallBack(mainContent);
        mainContent.setPlcSendMsg(plcServer);
        pool.execute(plcServer);
        pool.shutdown();
    }
}
